﻿Ext.namespace('iOS.BaseView');

Ext.define('BaseListView', {
    extend : 'BaseView',

    statics: {
        BaseCls       : 'list-view',
        ListContainer : 'list-container',
        ListCls       : 'ios-list',
        ListContent   : 'list-content',
        ListTarCard   : 'List-tar-card',
        AppCard       : 'app-card'
    },

    /*
     * 列表数据
     * 格式 {
           context : '',
           others  : *
       }
     */
    _listCfg: [],

    /*
     * 列表单击时候样式
     */
    _clickedColor: null,

    /*
     * 列表里的HTML结构,字符串形式的数组
     */
    _listHtml: [],

    _attachEventListener: function(){
        this.getElCacheByCls(this.self.ListCls).on('rangeclick', {scope : this}, this.clickHandler);
    },
    /*
     * 单击事件处理函数
     */
    clickHandler: function(e, el){
        var that  = e.data.scope || this,
            sttc  = that.self,
            $this = el ? $(el) : $(this),
            index = $this.index();
        $this.css('background', that._clickedColor);
        setTimeout(function(){
            $this.css('background', '');
        }, 550);
        iOS.ViewManager.notify(sttc.AppCard,   'changeCard',  [sttc.ListTarCard]);
    },

    _initInnerDom: function(){
        this._initListHtml();
        var listHtml = this._listHtml,
            sttc     = this.self,
            htmlData = 
            '<div style="width:100%;-webkit-box-flex:400;">' +
                '<div class="' + sttc.ListContainer + '">';
        for(var i = 0; i < listHtml.length; i++){
            htmlData +=
                '<div class="ios-list ' + sttc.ListCls + '">' +
                    listHtml[i] +
                '</div>';
        }
        htmlData += 
                '</div>'+
            '</div>';
        var config   = {
            direction  : 'vertical',
            bounces    : 'vertical'
        };
        this.getElCache().append(htmlData);
        var $el      = this.getElCacheByCls(sttc.ListContainer);
        $.scrollView($el.get(0), config); 
    },

    /*
     * 初始化列表里面的HTML
     */
    _initListHtml: function(){

    }
});

iOS.BaseView.BaseListView = BaseListView;